home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / vahunz.lha / vahunz / source / ubiqx / ubi_AVLtree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-17  |  5.5 KB  |  304 lines

  1. /*
  2.  * This source file is part of Vahunz,
  3.  * a tool to make source code un-/more legible.
  4.  *
  5.  *--------------------------------------------------------------------------
  6.  *
  7.  * Vahunz and the Ugly library are Copyright (C) 1998 by
  8.  * Thomas Aglassinger <agi@giga.or.at>
  9.  *
  10.  * All rights reserved.
  11.  *
  12.  * Refer to the manual for more information.
  13.  *
  14.  *--------------------------------------------------------------------------
  15.  *
  16.  * Ubiqx library is Copyright (C) 1991-1998 by
  17.  * Christopher R. Hertel <crh@ubiqx.mn.org>
  18.  *
  19.  * Ubiqx library is free software; you can redistribute it and/or
  20.  * modify it under the terms of the GNU Library General Public
  21.  * License as published by the Free Software Foundation; either
  22.  * version 2 of the License, or (at your option) any later version.
  23.  *
  24.  */
  25. #include "ubi_AVLtree.h" 
  26. #include <stdlib.h> 
  27. static char b9F[] = "ubi_AVLtree\n\
  28. \t$Revision: 2.5 $\n\
  29. \t$Date: 1997/12/23 04:00:42 $\n\
  30. \t$Author: crh $\n";
  31. static e6M L1( e6M p )
  32. {
  33. e6M j3J;
  34. j3J = p->e2Q[w6O];
  35. p->e2Q[w6O] = j3J->e2Q[e4E];
  36. j3J->e2Q[e4E] = p;
  37. j3J->e2Q[i0E] = p->e2Q[i0E];
  38. j3J->h1V = p->h1V;
  39. if(j3J->e2Q[i0E])
  40. (j3J->e2Q[i0E])->e2Q[(int)(j3J->h1V)] = j3J;
  41. p->e2Q[i0E] = j3J;
  42. p->h1V = e4E;
  43. if( p->e2Q[w6O] )
  44. {
  45. p->e2Q[w6O]->e2Q[i0E] = p;
  46. (p->e2Q[w6O])->h1V = w6O;
  47. }
  48. p->n7P -= q2Q( j3J->n7P );
  49. (j3J->n7P)--;
  50. return( j3J );
  51. static e6M R1( e6M p )
  52. {
  53. e6M j3J;
  54. j3J = p->e2Q[e4E];
  55. p->e2Q[e4E] = j3J->e2Q[w6O];
  56. j3J->e2Q[w6O] = p;
  57. j3J->e2Q[i0E] = p->e2Q[i0E];
  58. j3J->h1V = p->h1V;
  59. if(j3J->e2Q[i0E])
  60. (j3J->e2Q[i0E])->e2Q[(int)(j3J->h1V)] = j3J;
  61. p->e2Q[i0E] = j3J;
  62. p->h1V = w6O;
  63. if(p->e2Q[e4E])
  64. {
  65. p->e2Q[e4E]->e2Q[i0E] = p;
  66. p->e2Q[e4E]->h1V = e4E;
  67. }
  68. p->n7P -= q2Q( j3J->n7P );
  69. (j3J->n7P)++;
  70. return( j3J );
  71. static e6M L2( e6M j5L )
  72. {
  73. e6M j3J, l1B;
  74. j3J = j5L->e2Q[w6O];
  75. l1B = j3J->e2Q[e4E];
  76. j3J->e2Q[e4E] = l1B->e2Q[w6O];
  77. l1B->e2Q[w6O] = j3J;
  78. j5L->e2Q[w6O] = l1B->e2Q[e4E];
  79. l1B->e2Q[e4E] = j5L;
  80. l1B->e2Q[i0E] = j5L->e2Q[i0E];
  81. l1B->h1V = j5L->h1V;
  82. j5L->e2Q[i0E] = l1B;
  83. j5L->h1V = e4E;
  84. j3J->e2Q[i0E] = l1B;
  85. j3J->h1V = w6O;
  86. if( j5L->e2Q[w6O] )
  87. {
  88. j5L->e2Q[w6O]->e2Q[i0E] = j5L;
  89. j5L->e2Q[w6O]->h1V = w6O;
  90. }
  91. if( j3J->e2Q[e4E] )
  92. {
  93. j3J->e2Q[e4E]->e2Q[i0E] = j3J;
  94. j3J->e2Q[e4E]->h1V = e4E;
  95. }
  96. if(l1B->e2Q[i0E])
  97. l1B->e2Q[i0E]->e2Q[(int)(l1B->h1V)] = l1B;
  98. switch( l1B->n7P )
  99. {
  100. case e4E :
  101. j5L->n7P = g8I; j3J->n7P = w6O; break;
  102. case g8I:
  103. j5L->n7P = g8I; j3J->n7P = g8I; break;
  104. case w6O:
  105. j5L->n7P = e4E; j3J->n7P = g8I; break;
  106. }
  107. l1B->n7P = g8I;
  108. return( l1B );
  109. static e6M R2( e6M j5L )
  110. {
  111. e6M j3J, l1B;
  112. j3J = j5L->e2Q[e4E];
  113. l1B = j3J->e2Q[w6O];
  114. j3J->e2Q[w6O] = l1B->e2Q[e4E];
  115. l1B->e2Q[e4E] = j3J;
  116. j5L->e2Q[e4E] = l1B->e2Q[w6O];
  117. l1B->e2Q[w6O] = j5L;
  118. l1B->e2Q[i0E] = j5L->e2Q[i0E];
  119. l1B->h1V = j5L->h1V;
  120. j5L->e2Q[i0E] = l1B;
  121. j5L->h1V = w6O;
  122. j3J->e2Q[i0E] = l1B;
  123. j3J->h1V = e4E;
  124. if( j5L->e2Q[e4E] )
  125. {
  126. j5L->e2Q[e4E]->e2Q[i0E] = j5L;
  127. j5L->e2Q[e4E]->h1V = e4E;
  128. }
  129. if( j3J->e2Q[w6O] )
  130. {
  131. j3J->e2Q[w6O]->e2Q[i0E] = j3J;
  132. j3J->e2Q[w6O]->h1V = w6O;
  133. }
  134. if(l1B->e2Q[i0E])
  135. l1B->e2Q[i0E]->e2Q[(int)(l1B->h1V)] = l1B;
  136. switch( l1B->n7P )
  137. {
  138. case e4E :
  139. j5L->n7P = w6O; j3J->n7P = g8I; break;
  140. case g8I :
  141. j5L->n7P = g8I; j3J->n7P = g8I; break;
  142. case w6O :
  143. j5L->n7P = g8I; j3J->n7P = e4E; break;
  144. }
  145. l1B->n7P = g8I;
  146. return( l1B );
  147. static e6M t9D( e6M p, char l3J )
  148. {
  149. if( p->n7P != l3J )
  150. p->n7P += q2Q(l3J);
  151. else
  152. {
  153. char r5P; 
  154. r5P = p->e2Q[(int)l3J]->n7P;
  155. if( ( g8I == r5P ) || ( p->n7P == r5P ) )
  156. p = ( (e4E==l3J) ? R1(p) : L1(p) ); 
  157. else
  158. p = ( (e4E==l3J) ? R2(p) : L2(p) ); 
  159. }
  160. return( p );
  161. static e6M s0W( e6M g2I,
  162. e6M l9D,
  163. char l3J )
  164. {
  165. while( l9D )
  166. {
  167. l9D = t9D( l9D, l3J );
  168. if( i0E == l9D->h1V )
  169. return( l9D );
  170. if( g8I == l9D->n7P )
  171. return( g2I );
  172. l3J = l9D->h1V;
  173. l9D = l9D->e2Q[i0E];
  174. }
  175. return( g2I );
  176. static e6M h1T( e6M g2I,
  177. e6M l9D,
  178. char l3J )
  179. {
  180. while( l9D )
  181. {
  182. l9D = t9D( l9D, h3H(l3J) );
  183. if( i0E == l9D->h1V )
  184. return( l9D );
  185. if( g8I != l9D->n7P )
  186. return( g2I );
  187. l3J = l9D->h1V;
  188. l9D = l9D->e2Q[i0E];
  189. }
  190. return( g2I );
  191. static void b5P( e6M *u8S,
  192. e6M k2O,
  193. e6M t1D )
  194. {
  195. register int i;
  196. register int o0E = sizeof( v5T );
  197. for( i = 0; i < o0E; i++ )
  198. ((unsigned char *)t1D)[i] = ((unsigned char *)k2O)[i];
  199. (*u8S) = t1D;
  200. if(k2O->e2Q[e4E ] )
  201. (k2O->e2Q[e4E ])->e2Q[i0E] = t1D;
  202. if(k2O->e2Q[w6O] )
  203. (k2O->e2Q[w6O])->e2Q[i0E] = t1D;
  204. static void t3R( g8Sh v5F,
  205. e6M e8Uh,
  206. e6M c2U )
  207. {
  208. e6M *Parent;
  209. v5T p7D;
  210. e6M c0W = &p7D;
  211. if( e8Uh->e2Q[i0E] )
  212. Parent = &((e8Uh->e2Q[i0E])->e2Q[(int)(e8Uh->h1V)]);
  213. else
  214. Parent = (e6M *)&(v5F->k4S);
  215. b5P( Parent, e8Uh, c0W );
  216. if( c2U->e2Q[i0E] )
  217. Parent = &((c2U->e2Q[i0E])->e2Q[(int)(c2U->h1V)]);
  218. else
  219. Parent = (e6M *)&(v5F->k4S);
  220. b5P( Parent, c2U, e8Uh );
  221. if( c0W->e2Q[i0E] )
  222. Parent = &((c0W->e2Q[i0E])->e2Q[(int)(c0W->h1V)]);
  223. else
  224. Parent = (e6M *)&(v5F->k4S);
  225. b5P( Parent, c0W, c2U );
  226. e6M j3V( e6M l9P )
  227. {
  228. (void)y6S( (y8Ut)l9P );
  229. l9P->n7P = g8I;
  230. return( l9P );
  231. h3R m0C( g8Sh v5F,
  232. e6M i8C,
  233. y8Or x1B,
  234. e6M *j9B )
  235. {
  236. e6M y0U;
  237. if( !(j9B) ) j9B = &y0U;
  238. if( n5F( v5F,
  239. (y8Ut)i8C,
  240. x1B,
  241. (y8Ut *)j9B ) )
  242. {
  243. if( (*j9B) )
  244. i8C->n7P = (*j9B)->n7P;
  245. else
  246. {
  247. i8C->n7P = g8I;
  248. v5F->k4S = (y8Ut)s0W( (e6M)v5F->k4S,
  249. i8C->e2Q[i0E],
  250. i8C->h1V );
  251. }
  252. return( z1Zy );
  253. }
  254. return( d5B ); 
  255. e6M c6W( g8Sh v5F,
  256. e6M g4C )
  257. {
  258. y8Ut p,
  259. *r3Vg;
  260. if( (g4C->e2Q[e4E]) && (g4C->e2Q[w6O]) )
  261. t3R( v5F, g4C, l9B( g4C ) );
  262. if( g4C->e2Q[i0E] )
  263. r3Vg = (y8Ut *)
  264. &((g4C->e2Q[i0E])->e2Q[(int)(g4C->h1V)]);
  265. else
  266. r3Vg = &( v5F->k4S );
  267. if( g8I == g4C->n7P )
  268. (*r3Vg) = NULL;
  269. else
  270. {
  271. p = (y8Ut)(g4C->e2Q[(int)(g4C->n7P)]);
  272. p->e2Q[i0E] = (y8Ut)g4C->e2Q[i0E];
  273. p->h1V = g4C->h1V;
  274. (*r3Vg) = p;
  275. }
  276. v5F->k4S = (y8Ut)h1T( (e6M)v5F->k4S,
  277. g4C->e2Q[i0E],
  278. g4C->h1V );
  279. (v5F->count)--;
  280. return( g4C );
  281. int z7Zy( int u0Qh, char *list[] )
  282. {
  283. if( u0Qh > 0 )
  284. {
  285. list[0] = b9F;
  286. if( u0Qh > 1 )
  287. return( 1 + r7F( --u0Qh, &(list[1]) ) );
  288. return( 1 );
  289. }
  290. return( 0 );
  291.